<template>
<div>
    <van-nav-bar
      title="设置昵称"
      left-text="取消"
      right-text="完成"
      @click-left="$emit('close')"
      @click-right="updateName"
       />
      <van-field
      v-model="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="7"
      placeholder="请输入留言"
      show-word-limit
    />
</div>
</template>

<script>
import { updateUserName } from '@/api/user'
export default {
  components: {},
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      message: ''
    }
  },
  computed: {},
  watch: {},
  created () {
    // value是prop 只能读不能改
    // message是自己的私有数据 data，
    this.message = this.value
  },
  mounted () {},
  methods: {
    async updateName () {
      try {
        await updateUserName({
          name: this.message
        })
        this.$emit('update-name', this.message)
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped>

</style>
